#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>


#define __cycle_start(t)    \
do{\
    struct timeval qwtyop_tvs, qwtyop_tve;\
    gettimeofday(&qwtyop_tvs, NULL); \
    while(1) {  \
        static int kidx = 0;\
        if(kidx++ >= t) {\
            break;\
        }

#define __cycle_end(usec)\
    }\
    gettimeofday(&qwtyop_tve, NULL);\
    usec = (int64_t)(qwtyop_tve.tv_sec-qwtyop_tvs.tv_sec)*(int64_t)1000000 + (int64_t)(qwtyop_tve.tv_usec-qwtyop_tvs.tv_usec);\
}while(0);



int main()
{
    int64_t usec;

    struct timeval tv;
    struct timespec ts;

    __cycle_start(1000000)
    gettimeofday(&tv, NULL);
    __cycle_end(usec)
    printf("used %lld usec.\n", usec);

    __cycle_start(1000000)
    //clock_gettime(CLOCK_MONOTONIC, &ts);
    clock_gettime(CLOCK_REALTIME, &ts);
    __cycle_end(usec)
    printf("used %lld usec.\n", usec);

    return 0;
}
